﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Derrick.AttackTest
{

    public partial class MainForm : Form
    {

        private Thread _attackThread = null;
        private SpoofService _spoofingThread = null;

        public MainForm()
        {
            InitializeComponent();
        }

        private void startToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _attackThread = new Thread(new ThreadStart(Spoofing));
            _attackThread.Start();
        }

        private void Spoofing()
        {
            _spoofingThread = new SpoofService();
            _spoofingThread.RaiseSelectDeviceEvent += new EventHandler<SelectDeviceEventArgs>(_spoofingThread_RaiseSelectDeviceEvent);
            _spoofingThread.RaiseListeningToDeviceEvent += new EventHandler<ListeningToDeviceEventArgs>(_spoofingThread_RaiseListeningToDeviceEvent);
            _spoofingThread.StartSpoofing();
        }

        void _spoofingThread_RaiseListeningToDeviceEvent(object sender, ListeningToDeviceEventArgs args)
        {
            MessageBox.Show(args.Message);
        }

        void _spoofingThread_RaiseSelectDeviceEvent(object sender, SelectDeviceEventArgs args)
        {
            SelectDevice selectDeviceWindow = new SelectDevice();
            selectDeviceWindow.ShowDialog();

        }

        private void stopToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (null != _attackThread)
            {
                _attackThread.Join();
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void configureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetSpoofParameters setSpoofParams = new SetSpoofParameters();
            setSpoofParams.Show();
        }
    }
}
